﻿using UnityEngine;
using System.Collections;
using Common;
using System.Collections.Generic;

public delegate void OnDelegateFunc(Notification node);
public class NotficationCenter :OrdinarySingleton<NotficationCenter>
{
    private Dictionary<string, OnDelegateFunc> mapFunc = new Dictionary<string, OnDelegateFunc>();

    public void AddNotificationEvent(string key,OnDelegateFunc func)
    {
        if (!mapFunc.ContainsKey(key))
        {
            mapFunc[key] = null;
        }
        mapFunc[key] += func;
    }

    public void RemoveNotificationEvent(string key,OnDelegateFunc func)
    {
        if (!mapFunc.ContainsKey(key))
        {
            return;
        }
        mapFunc[key] -= func;
    }

    public void RemoveAllNotificationEvent(string key)
    {
        mapFunc[key] = null;
    }

    public void PostNotificationEvent(string key,Notification node = null)
    {
        if (!mapFunc.ContainsKey(key))
        {
            return;
        }
        mapFunc[key](node);
    }

}

